import BaseWindow from "../common/BaseWin";
import RankLayer from "./RankLayer";


export default class RankDialog extends BaseWindow {
  private _timeId: any = null;
  tipslayer: RankLayer;

  constructor() {
    super();
    this.contentPane = this.tipslayer = RankLayer.createInstance();

    let scaleX =
      fgui.GRoot.inst.width / cc.view.getDesignResolutionSize().width;
    let scaleY =
      fgui.GRoot.inst.height / cc.view.getDesignResolutionSize().height;
    this.contentPane.width *= scaleX;
    this.contentPane.height *= scaleY;

    this.center();
    this.modal = true;
    this.tipslayer.setContainer(this);
  }

  /**
   * @param tipStr title
   * @param level 0:ok 1:warning 2:error
   * @param bAutoClose 自动关闭
   * @param bShowCancel 显示取消按钮
   * @param bImmediately 点击立即关闭
   */
  showEx(
    tipStr: string,
    level = 0,
    bAutoClose = true,
    bShowCancel = false,
    bImmediately = false
  ): void {
    if (this.hideCallback != null) {
      this.tipslayer._confirmCB = this.hideCallback;
    }
    // this.contentPane.getController("c1").selectedIndex = level - 1;
    // this.contentPane.getController("showCancelBtn").selectedIndex = bShowCancel
    //   ? 1
    //   : 0;
    // if (!tipStr) tipStr = "未知的错误";
    RankLayer.bImmediatelyHide = bImmediately;
    // this.tipslayer.m_contentTxt.text = tipStr;
    this.show();
    if (this._timeId) {
      clearTimeout(this._timeId);
    }
    if (bAutoClose) {
      this._timeId = setTimeout(() => {
        this._timeId = null;
        this.hide();
      }, 3000);
    }
  }
}
